package com.blog.wl2023.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @author wule
 * @desc
 */
public class CommUtil {

	/*随机生成6位数的验证码*/
	public static String generateRandomCode(int codeLength) {
		Random random = new Random();
		StringBuilder codeBuilder = new StringBuilder();
		for (int i = 0; i < codeLength; i++) {
			int digit = random.nextInt(10); // 生成0-9之间的随机数
			codeBuilder.append(digit);
		}
		return codeBuilder.toString();
	}



	/**
	 * 返回当前的年月字符串，示例：2021-08
	 *
	 * @return 年月字符串
	 */
	public static String getYearMonth() {
		//yyyyMMdd
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		return sdf.format(new Date());
	}


}
